package com.winchain.chainbill.bill.biz.report.controller;

import com.shell.bee.base.annotation.Logging;
import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.CommonFileUtil;
import com.shell.framework.utils.SysDateUtil;
import com.winchain.chainbill.bill.biz.discount.vo.DctCalculatedInterestInfoVO;
import com.winchain.chainbill.bill.biz.discount.vo.DctCalculatedInterestQueryVO;
import com.winchain.chainbill.bill.biz.discount.vo.DctInterestBusinessDailyEarnTotalVO;
import com.winchain.chainbill.bill.biz.receive.vo.DelayCalculatedInterestInfoVO;
import com.winchain.chainbill.bill.biz.receive.vo.DelayCalculatedInterestQueryVO;
import com.winchain.chainbill.bill.biz.receive.vo.DelayCalculatedInterestTotalVO;
import com.winchain.chainbill.bill.biz.report.service.BillReportQueryService;
import com.winchain.chainbill.util.ExcelGenUtil;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BillReportController {
	@Autowired
	private BillReportQueryService billReportQueryService;

	@RequestMapping
	@ResponseBody
	@Logging(module = "����", methods = "��������������������")
	public DelayCalculatedInterestTotalVO selectDelayCalculatedInterestTotal(
			DelayCalculatedInterestQueryVO delayCalculatedInterestQueryVO) {
		delayCalculatedInterestQueryVO.setFinId(CommonDataUtil.getCurEntId());
		return this.billReportQueryService.selectDelayCalculatedInterestTotal(delayCalculatedInterestQueryVO);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "����", methods = "����������������")
	public List<DelayCalculatedInterestInfoVO> selectDelayCalculatedInterestByPage(PageLimit limit,
			DelayCalculatedInterestQueryVO delayCalculatedInterestQueryVO) {
		delayCalculatedInterestQueryVO.setFinId(CommonDataUtil.getCurEntId());
		return this.billReportQueryService.selectDelayCalculatedInterestByPage(limit, delayCalculatedInterestQueryVO);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "����", methods = "����������������")
	public void exportDelayIntList(PageLimit limit, DelayCalculatedInterestQueryVO delayCalculatedInterestQueryVO,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap();
		delayCalculatedInterestQueryVO.setFinId(CommonDataUtil.getCurEntId());
		map.put("datas",
				this.billReportQueryService.selectDelayCalculatedInterestByPage(limit, delayCalculatedInterestQueryVO));
		InputStream is = ExcelGenUtil.getInstance().GenerateExcelForStream("/template/excel/delayIntReportList.xlsx",
				map);
		CommonFileUtil.writeFileToClient("��������" + delayCalculatedInterestQueryVO.getAcrMonth() + ".xlsx", is,
				response, request);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "����������������")
	public List<DctCalculatedInterestInfoVO> selectDctCalculatedInterestList(PageLimit limit,
			DctCalculatedInterestQueryVO dctCalculatedInterestQueryVO) {
		String curEntId = CommonDataUtil.getCurEntId();
		dctCalculatedInterestQueryVO.setCurEntId(curEntId);
		return this.billReportQueryService.selectDctCalculatedInterestByPage(limit, dctCalculatedInterestQueryVO);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "����������������")
	public void exportDctIntList(PageLimit limit, DctCalculatedInterestQueryVO dctCalculatedInterestQueryVO,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		Map<String, Object> map = new HashMap();
		String curEntId = CommonDataUtil.getCurEntId();
		dctCalculatedInterestQueryVO.setCurEntId(curEntId);
		map.put("datas",
				this.billReportQueryService.selectDctCalculatedInterestByPage(limit, dctCalculatedInterestQueryVO));
		map.put("totalDatas",
				this.billReportQueryService.selectDctInterestBusinessDailyEarnTotal(dctCalculatedInterestQueryVO));
		InputStream is = ExcelGenUtil.getInstance().GenerateExcelForStream("/template/excel/dctIntReportList.xlsx",
				map);
		CommonFileUtil.writeFileToClient("��������-" + dctCalculatedInterestQueryVO.getMonth() + ".xlsx", is, response,
				request);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "��������������������������������")
	public DctInterestBusinessDailyEarnTotalVO selectDctInterestBusinessDailyEarnTotal(
			DctCalculatedInterestQueryVO dctCalculatedInterestQueryVO) {
		String curEntId = CommonDataUtil.getCurEntId();
		dctCalculatedInterestQueryVO.setCurEntId(curEntId);
		return this.billReportQueryService.selectDctInterestBusinessDailyEarnTotal(dctCalculatedInterestQueryVO);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "��������������������������������")
	public List<DctInterestBusinessDailyEarnTotalVO> selectDctInterestBusinessDailyEarnTotalForChart(
			DctCalculatedInterestQueryVO dctCalculatedInterestQueryVO) {
		String curEntId = CommonDataUtil.getCurEntId();
		dctCalculatedInterestQueryVO.setCurEntId(curEntId);
		String startMonth = dctCalculatedInterestQueryVO.getStartMonth();
		String endMonth = dctCalculatedInterestQueryVO.getEndMonth();
		if (StringUtil.notEmpty(startMonth)) {
			dctCalculatedInterestQueryVO.setStartMonth(SysDateUtil.parseDate(startMonth, "yyyy-MM", "yyyyMM"));
		}
		if (StringUtil.notEmpty(endMonth)) {
			dctCalculatedInterestQueryVO.setEndMonth(SysDateUtil.parseDate(endMonth, "yyyy-MM", "yyyyMM"));
		}
		return this.billReportQueryService
				.selectDctInterestBusinessDailyEarnTotalForChart(dctCalculatedInterestQueryVO);
	}
}
